﻿// JavaScript Document
$(document).ready(function(){
					$('#dituContent').prepend('<div id="measure" onClick="measure()">测距</div>');
					$('.ship_type_table td').click(function(){
						$('.ship_type_table td').removeClass('isSelected');
						$(this).addClass('isSelected');
						if($(this).attr('id')=='inshore'){
							$('.inshore_ships').show();
							$('.ocean_ships').hide();
							if($('.Choose').length==0){
							clearoverlay();
							create_inshore();
							}
						}
						else{
							$('.inshore_ships').hide();
							$('.ocean_ships').show();
							if($('.Choose').length==0){
							clearoverlay();
							create_ocean();
							}
						}
					});
					$('.ships li').click(function(){
						//已选择，点击取消选择，删除船只
						if($(this).attr('class')=='Choose'){
							$(this).removeClass("Choose");
							$(this).children('span').removeClass('selected');
							deleteship($(this).attr('id'));
							var pointarray;//存放路线坐标
							removePolyline([[116.513907,39.998299,132.261993,23.227216,138.296307,30.417089,116.366729,39.941675]]);
							}
						else{
							//点击选择，获取点击船只的各项信息，添加船只
							$(this).addClass('Choose');
							if($('.Choose').length==1){
								clearoverlay();
						}
							$(this).children('span').addClass('selected')
							create_ship($(this).attr('id'));
							}
						
					});
					select_time();
					$('#searchbtn').click(function(){
						if($('.Choose').length!=0&&$('#from2').val()!=''&&$('#to2').val()!=''){
							//根据所选船只和时间段获取船只当前位置和路线坐标数组
							for(var i=1;i<=$('.Choose').length;i++){
							addPolyline(["116.513907|39.998299","132.261993|23.227216","138.296307|30.417089","116.366729|39.941675"]);//向地图中添加线
							}
							}
						else if($('.Choose').length==0){
							alert('请先选择查询船只');
							}
						else {
							alert('请先选择查询时间');
							
							}
						});
					
						   });
	function select_time(){
					$("input[name=from]").datepicker({
						dateFormat:'yy-mm-dd',
						defaultDate: "+1w",
						changeMonth: true,
						monthNames: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],   
						monthNamesShort: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
						numberOfMonths: 1,
						onClose: function( selectedDate ) {
							$(this).siblings('input[name=to]').datepicker( "option", "minDate", selectedDate);
							}
						});
					$("input[name=to]").datepicker({
						dateFormat:'yy-mm-dd',
						defaultDate: "+1w",
						changeMonth: true,
						monthNames: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],   
						monthNamesShort: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
						numberOfMonths:1,
						onClose: function( selectedDate ) {
							$(this).siblings('input[name=from]').datepicker( "option", "maxDate", selectedDate );
							}
							});
					}
			function infobox(){
						select_time();
						$('.time_search').click(function(){
						if($('#from').val()!=''&&$('#to').val()!=''){
							var select_ship_name=$('#select_ship_name').text();
							$shipinfo.remove();
							//根据所选船只和时间段获取船只当前位置和路线坐标数组
							addPolyline(["116.513907|39.998299","132.261993|23.227216","138.296307|30.417089","116.366729|39.941675"]);//向地图中添加线
							}
						else{
							alert('请先选择航行时间')
							}
						});	
						$('#close_img').click(function(){
							$('.ship_info').remove();
							});
				}